<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>流程列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.5.4/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layui-tab" lay-filter="demo">
        <ul class="layui-tab-title">
            <li data-status="1" class="layui-this">待审批</li>
            <li data-status="3">审批通过</li>
            <li data-status="2">审批驳回</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <table class="layui-hide" id="workflowApply" lay-filter="workflow"></table>
                <script type="text/html" id="workflowApplyBar">
                    <a class="layui-btn layui-btn-xs" lay-event="workflowApplyEvent">审批</a>
                </script>
            </div>
            <div class="layui-tab-item">
                <table class="layui-hide" id="workflowPass" lay-filter="workflow"></table>
                <script type="text/html" id="workflowPassBar">
                    <a class="layui-btn layui-btn-xs" lay-event="workflowPassEvent">查看</a>
                </script>
            </div>
            <div class="layui-tab-item">
                <table class="layui-hide" id="workflowReject" lay-filter="workflow"></table>
                <script type="text/html" id="workflowRejectBar">
                    <a class="layui-btn layui-btn-xs" lay-event="workflowRejectEvent">查看</a>
                </script>
            </div>
        </div>
    </div>
</div>
</body>
<script src="/lib/layui-v2.5.4/layui.js" charset="utf-8"></script>
<script th:inline="javascript">
    /*<![CDATA[*/
    layui.use(['table', 'element'], function () {
        var table = layui.table,
            $ = layui.jquery,
            element = layui.element;

        // 初始化加载
        getList('#workflowApply', 1, '#workflowApplyBar');
        //一些事件监听
        element.on('tab(demo)', function (data) {
            var statusId = $(this).attr('data-status');
            var position = '#workflowApply';
            var bar = '#workflowApplyBar';
            switch (statusId) {
                case '1':
                    position = '#workflowApply';
                    bar = '#workflowApplyBar';
                    break;
                case '3':
                    position = '#workflowPass';
                    bar = '#workflowPassBar';
                    break;
                case '2':
                    position = '#workflowReject';
                    bar = '#workflowRejectBar';
                    break;
                default:
                    position = '#workflowApply';
                    bar = '#workflowApplyBar';
            }
            getList(position, statusId, bar)
        });

        // 公共方法
        function getList(position, statusId, bar) {
            // 表格
            table.render({
                elem: position,
                url: '/api/admin/workflow/task/list',
                where: {
                    statusId: statusId
                },
                page: true,
                cols: [
                    [
                        {field: 'id', title: 'ID', align: 'center', hide: true},
                        {field: 'accountName', title: '申请人', align: 'center'},
                        {field: 'licenseName', title: '申请事项', align: 'center'},
                        {
                            field: 'startTime',
                            title: '申请时间',
                            align: 'center',
                            templet: '<div>{{ layui.util.toDateString(d.birthData, "yyyy-MM-dd ") }}</div>'
                        },
                        {field: 'workFlowId', title: '流程ID', align: 'center', hide: true},
                        {fixed: 'right', title: '操作', toolbar: bar, align: 'center'}
                    ]
                ]
            });
        }

        //监听工具条
        table.on('tool(workflow)', function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            if (layEvent === 'workflowApplyEvent') {
                window.location = "/admin/workflow/task/approve?eventId=" + data.id;
            } else if (layEvent === 'workflowPassEvent') {
                window.location = "/admin/workflow/task/pass/view?eventId=" + data.id;
            } else if (layEvent === 'workflowRejectEvent') {
                window.location = "/admin/workflow/task/reject/view?eventId=" + data.id;
            }
        });
    });
    /*]]>*/
</script>
</html>